Check ls-tree Mode, Not Type, to Exclude a Symlink - #1020
Conversation
A symlink's git ls-tree type is 'blob' too, the same as a regular file: only its mode (120000) differs. Checking entry type alone let a file-to-symlink transition through as file content, and git show on a symlink revision returns the link's target path string, not the content it points to, so that string would be hashed and compared as if it were the file's real text. Check the ls-tree mode field directly instead of the type: only 100644 (regular) and 100755 (executable) count as file content: everything else (040000 tree, 120000 symlink, 160000 gitlink, or absent) reads as None. Added a self-test covering a file-to-symlink transition. ## Validation - python3 spec/audit.py --selftest - uvx ruff check / uvx ruff format --check spec/audit.py - uvx mypy spec/audit.py - python3 scripts/prose_lint.py (full check set) - python3 scripts/repo_gate.py Raised by CodeRabbit on PR #1016 (develop -> main promotion).
PR Summary by QodoExclude Symlinks from Git Revision Content Using ls-tree Modes
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthrough
ChangesGit revision handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change prevents symlink revisions from being treated as regular file content by checking Git modes directly. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Code Review by Qodo
1.
|
Path.symlink_to() raises OSError on a host or user lacking symlink-creation privilege, notably Windows without Developer Mode or an elevated prompt. Calling it unconditionally in the self-test would abort the whole --selftest run on such a host, before it could report any result at all, over an environment limitation rather than a code fault. Wrap the symlink creation in try/except OSError and skip only that one case with a printed note when it fails, leaving every other self-test case (including the rest of _git_revisions' own coverage) unaffected. ## Validation - python3 spec/audit.py --selftest - uvx ruff check / uvx ruff format --check spec/audit.py - uvx mypy spec/audit.py - python3 scripts/prose_lint.py (full check set) - python3 scripts/repo_gate.py Raised by qodo on PR #1020.
Summary
A symlink's
git ls-treetype isblobtoo, the same as a regular file: only its mode (120000) differs. Checking entry type alone let a file-to-symlink transition through as file content, andgit showon a symlink revision returns the link's target path string, not the content it points to, so that string would be hashed and compared as if it were the file's real text.Fix
Check the ls-tree mode field directly instead of the type: only
100644(regular) and100755(executable) count as file content, everything else (040000tree,120000symlink,160000gitlink, or absent) reads as None. Added a self-test covering a file-to-symlink transition.Validation
python3 spec/audit.py --selftestuvx ruff check/uvx ruff format --check spec/audit.pyuvx mypy spec/audit.pypython3 scripts/prose_lint.py(full check set)python3 scripts/repo_gate.pyRaised by CodeRabbit on PR #1016 (develop -> main promotion).
🤖 Generated with Claude Code
Summary by CodeRabbit